﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBModule;
using System.Data.SqlClient;
using System.Data;

namespace DataLogical.TableClass
{
    #region tblCheckListForOtherCivilServant
    /// <summary>
    /// This object represents the properties and methods of a tblCheckListForOtherCivilServant.
    /// </summary>

    public class tblCheckListForOtherCivilServant
    {
        protected int _iD;
        protected bool _checkItem01;
        protected bool _checkItem02;
        protected bool _checkItem03;
        protected bool _checkItem04;
        protected bool _checkItem05;
        protected bool _checkItem06;

        public tblCheckListForOtherCivilServant()
        {
        }

        public tblCheckListForOtherCivilServant(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("SELECT ID,CheckItem01,CheckItem02,CheckItem03,CheckItem04,CheckItem05,CheckItem06 FROM tblCheckListForOtherCivilServant WHERE ID = {0}", ID);
            SqlDataReader reader = db.FastQueryBySql(strSql);
            if (reader.Read())
            {
                this.LoadFromReader(reader);
                reader.Close();
            }
            else
            {
                if (!reader.IsClosed) reader.Close();
                throw new ApplicationException("tblCheckListForOtherCivilServant does not exist.");
            }
        }

        public tblCheckListForOtherCivilServant(SqlDataReader reader)
        {
            this.LoadFromReader(reader);
        }

        protected void LoadFromReader(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                _iD = reader.GetInt32(0);
                if (!reader.IsDBNull(1)) _checkItem01 = reader.GetBoolean(1);
                if (!reader.IsDBNull(2)) _checkItem02 = reader.GetBoolean(2);
                if (!reader.IsDBNull(3)) _checkItem03 = reader.GetBoolean(3);
                if (!reader.IsDBNull(4)) _checkItem04 = reader.GetBoolean(4);
                if (!reader.IsDBNull(5)) _checkItem05 = reader.GetBoolean(5);
                if (!reader.IsDBNull(6)) _checkItem06 = reader.GetBoolean(6);
            }
        }

        public void Delete(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("Delete From tblCheckListForOtherCivilServant Where ID={0}", ID);
            db.ExecSql(strSql);
        }

        public DataTable GetAll()
        {
            string strSql = "SELECT ID,CheckItem01,CheckItem02,CheckItem03,CheckItem04,CheckItem05,CheckItem06 FROM tblCheckListForOtherCivilServant";
            SqlModule db = CommonVar.s_SqlModule;
            return db.QueryBySql(strSql);
        }

        public int Insert(tblCheckListForOtherCivilServant obj)
        {
            int rtn = 0;
            string strSql = "Insert Into tblCheckListForOtherCivilServant(CheckItem01,CheckItem02,CheckItem03,CheckItem04,CheckItem05,CheckItem06)Values(@CheckItem01,@CheckItem02,@CheckItem03,@CheckItem04,@CheckItem05,@CheckItem06);SELECT @@IDENTITY";
            SqlModule db = CommonVar.s_SqlModule;
            SqlModule.ParameterCollection Params = CreateParams(obj);
            DataTable dt = db.QueryBySql(strSql, Params);
            if (dt.Rows.Count == 1)
            {
                rtn = int.Parse(dt.Rows[0][0] + "");
            }
            return rtn;
        }

        public void Update(tblCheckListForOtherCivilServant obj)
        {
            string strSql = string.Format("Update tblCheckListForOtherCivilServant Set CheckItem01=@CheckItem01,CheckItem02=@CheckItem02,CheckItem03=@CheckItem03,CheckItem04=@CheckItem04,CheckItem05=@CheckItem05,CheckItem06=@CheckItem06 Where ID={0}", obj.ID);
            SqlModule db = CommonVar.s_SqlModule;
            SqlModule.ParameterCollection Params = CreateParams(obj);
            db.ExecSql(strSql, Params);
        }

        private SqlModule.ParameterCollection CreateParams(tblCheckListForOtherCivilServant obj)
        {
            SqlParameter Param;
            SqlModule.ParameterCollection Result = new SqlModule.ParameterCollection();

            Param = new SqlParameter("@CheckItem01", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem01 != null)
            {
                Param.Value = obj.CheckItem01;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@CheckItem02", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem02 != null)
            {
                Param.Value = obj.CheckItem02;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@CheckItem03", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem03 != null)
            {
                Param.Value = obj.CheckItem03;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@CheckItem04", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem04 != null)
            {
                Param.Value = obj.CheckItem04;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@CheckItem05", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem05 != null)
            {
                Param.Value = obj.CheckItem05;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            Param = new SqlParameter("@CheckItem06", SqlDbType.Bit);
            Result.Add(Param);
            if (obj.CheckItem06 != null)
            {
                Param.Value = obj.CheckItem06;
            }
            else
            {
                Param.Value = DBNull.Value;
            }
            return Result;
        }

        public static bool Exist(int ID)
        {
            SqlModule db = CommonVar.s_SqlModule;
            string strSql = string.Format("SELECT COUNT(*) From tblCheckListForOtherCivilServant Where ID={0}", ID);
            return (db.ExecSql_Cnt(strSql) == 1);
        }

        #region Public Properties
        public int ID
        {
            get { return _iD; }
        }

        public bool CheckItem01
        {
            get { return _checkItem01; }
            set { _checkItem01 = value; }
        }

        public bool CheckItem02
        {
            get { return _checkItem02; }
            set { _checkItem02 = value; }
        }

        public bool CheckItem03
        {
            get { return _checkItem03; }
            set { _checkItem03 = value; }
        }

        public bool CheckItem04
        {
            get { return _checkItem04; }
            set { _checkItem04 = value; }
        }

        public bool CheckItem05
        {
            get { return _checkItem05; }
            set { _checkItem05 = value; }
        }

        public bool CheckItem06
        {
            get { return _checkItem06; }
            set { _checkItem06 = value; }
        }
        #endregion
    }
    #endregion
}
